﻿
var ok=false;
var code ;
function createCode(){
    code = "";
    var codeLength = 4;
    var selectChar = new Array(1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f','g','h','j','k','l','m','n','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z');
    for(var i=0;i<codeLength;i++) {
       var charIndex = Math.floor(Math.random()*60);
      code +=selectChar[charIndex];
    }
    if(code.length != codeLength){
      createCode();
    }
    showCheck(code);
    ok=false;
}

function showCheck(a){
  var c = document.getElementById("myCanvas");
  var ctx = c.getContext("2d");
  ctx.clearRect(0,0,1000,1000);
  ctx.font = "80px 'Microsoft Yahei'";
  ctx.fillText(a,0,100);
  ctx.fillStyle = "white";
}


$(function(){

  var ok1 = false;
  $('#J_codetext').keyup(function(event) {
      if($('#J_codetext').val().toLowerCase()!=code.toLowerCase()){
            ok = false;
        }else{
            ok = true;
        }
  });


  $("#email").keyup(function() {
        var str = $("#email").val();
        var ret = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
        if(ret.test(str)){
            ok1 = true;
        }else{
            ok1 = false;
        }
    });

  $("#email").blur(function() {
      var str = $("#email").val();
      var ret = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
      if(ret.test(str)){
          ok1 = true;
      }else{
          ok1 = false;
      }
  });
  
  //点击确定按钮隐藏
  $('.btn').on('click',function(){
    $('.bg').removeClass('blur');
    $('.popus,.mask').hide();
  });

  //点击确定按钮隐藏
  $('.btn1').on('click',function(){
    $('.bg').removeClass('blur');
    $('.popus1,.mask').hide();
  });



  $('#submit_btn').click(function(){
        if( ok && ok1){
            $('form').submit();
        }else{

            if(!ok1){
              console.log(98)
              $('.bg').addClass('blur');
              $('.popus1,.mask').show();
              return;

            }
            if(!ok){
              console.log(98)
              $('.bg').addClass('blur');
              $('.popus,.mask').show();
              return;
            }
      }
  });

});
